﻿using System;

namespace PacketRush.Services.Commanding
{
    /// <summary>
    /// Abstract base class for commands
    /// </summary>
    public abstract class Command
    {
        /// <summary>
        /// Raised when the command is executed
        /// </summary>
        public event EventHandler<CommandEventArgs> Execute;

        /// <summary>
        /// Called when the command is executed
        /// </summary>
        /// <param name="args"></param>
        protected void OnExecute(params string[] args)
        {
            if (Execute != null)
            {
                Execute(this, new CommandEventArgs(this, args));
            }
        }

        /// <summary>
        /// The name of this command
        /// </summary>
        public abstract string CommandName { get; }
        
        /// <summary>
        /// Execute this command with the given arguments
        /// </summary>
        /// <param name="args">Command arguments</param>
        public virtual void ExecuteCommand(params string[] args)
        {
            OnExecute(args);
        }
    }
}